// 收集数据 → 发请求 → 提示成功或失败 → 缓存用户名和token → 跳转页面
document.querySelector('#btn-login').addEventListener('click', async function() {
  const data = serialize(document.querySelector('.login-form'), {hash: true, empty: true})
  const {username, password} = data
  if (username=='' || password == '') return showToast('用户名和密码不能为空') 
  if (username.length<8||username.length>30 || password.length<6 || password.length>30) return showToast('用户名长度8-30， 密码长度6-30')

  try {
    const res = await axios.post('/login', data)
    showToast(res.message)
    localStorage.setItem('username', res.data.username)
    localStorage.setItem('token', res.data.token)
    setTimeout(() => {
      location.href = './index.html'
    }, 1500);
  } catch (error) {
    console.dir(error)
    
  }
})


// ceshi